﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    //增加鉴权属性
    [Authorize]
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }
        #region 基于角色认证

        //[Authorize(Roles ="SVip")]
        //public string SVip() {
        //    return "this is SVip";
        //}
        //[Authorize(Roles = "Vip,SVip")]
        //public string Vip()
        //{
        //    return "this is Vip";
        //}
        //[Authorize(Roles = "NoVip")]
        //public string NoVip()
        //{
        //    return "this is NoVip";
        //}
        #endregion
        #region 基于策略认证

        [Authorize(Policy  = "SVip")]
        public string SVip()
        {
            return "this is SVip";
        }
        [Authorize(Policy = "Vip")]
        public string Vip()
        {
            return "this is Vip";
        }
        [Authorize(Policy = "NoVip")]
        public string NoVip()
        {
            return "this is NoVip";
        }
        #endregion
        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
